home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / ex / ex8-11.c < prev    next >
C/C++ Source or Header  |  1990-05-29  |  926b  |  31 lines

  1. // ex8-11.c -- Test if date falls on a weekday
  2.  
  3. // $Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/ex/RCS/ex8-11.c,v 3.0 90/05/29 14:34:17 kgorlen Rel $
  4.  
  5. #include "Date.h"
  6. #include "Set.h"
  7. #include "String.h"
  8.  
  9. main ()
  10. {
  11.     Set weekdays;       // Set of weekday names
  12.     String mon = "Monday", tue = "Tuesday", wed = "Wednesday",
  13.         thu = "Thursday", fri = "Friday";
  14.     weekdays.add(mon);  weekdays.add(tue);  weekdays.add(wed);
  15.         weekdays.add(thu);  weekdays.add(fri);
  16.  
  17.     Date date;
  18.     while (YES) {
  19.         cout << "Enter date: ";  cin >> date;
  20.         if (cin.eof()) break;
  21. // Convert date to String containing name of day and
  22. // search Set for match
  23.         if (weekdays.includes(
  24.             String(Date::nameOfDay(date.weekDay()))))
  25.             cout << date << " is a weekday" << endl;
  26.         else
  27.             cout << date << " is not a weekday" << endl;
  28.     }
  29.     cout << endl;
  30. }
  31.